package com.example.module_vip.adapter

import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.module_vip.vip.AppointmentsList
import  com.example.module_vip.R
import com.example.module_vip.vip.AppointmentsListItem

class VipAdapter : RecyclerView.Adapter<VipAdapter.VipViewHolder>() {

    private val data = mutableListOf<AppointmentsListItem>()

    fun setData(data: MutableList<AppointmentsListItem>) {
        this.data.clear()
        this.data.addAll(data)

        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VipViewHolder {

        return VipViewHolder(
            LayoutInflater.from(parent.context).inflate(R.layout.item_vip, parent, false)
        )
    }

    override fun getItemCount() = data.size

    override fun onBindViewHolder(holder: VipViewHolder, position: Int) {
        holder.shijian_vip.text = "${data[position].appointmentTime}"
        holder.name_vip.text = "${data[position].visitorName}"
        holder.laifangshiyou_vip.text = "${data[position].purpose}"
        holder.fangwenduixaing_vip.text = "${data[position].employeeId}"
        holder.fangwenduixaing_vip.text = "${data[position].employeeId}"
        when (data[position].requestParking) {
            true -> {
                holder.shifoushenqingchewei_vip.text =
                    "已申请访客车位:${data[position].plateNumber}"
                holder.shifoushenqingchewei_vip.setTextColor(Color.BLUE)
            }

            false ->{
                holder.shifoushenqingchewei_vip.text = "未申请访客车位"
                holder.shifoushenqingchewei_vip.setTextColor(Color.GRAY)
            }
        }

        holder.shifoutongguo_vip.text = "${data[position].visitStatus}"

        when (data[position].visitStatus) {
            "已通过" ->{
                holder.shifoutongguo_vip.setTextColor(Color.BLACK)
                holder.shifoutongguo_vip.setBackgroundColor(Color.GREEN)
            }
            "驳回" -> {
                holder.shifoutongguo_vip.setTextColor(Color.BLACK)
                holder.shifoutongguo_vip.setBackgroundColor(Color.RED)
            }
            "待审核"->{
                holder.shifoutongguo_vip.setTextColor(Color.BLACK)
                holder.shifoutongguo_vip.setBackgroundColor(Color.GRAY)
            }
        }
    }


    inner class VipViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        var shijian_vip: TextView
        var name_vip: TextView
        var laifangshiyou_vip: TextView
        var fangwenduixaing_vip: TextView
        var shifoushenqingchewei_vip: TextView
        var shifoutongguo_vip: TextView

        init {
            shijian_vip = view.findViewById(R.id.shijian_vip)
            name_vip = view.findViewById(R.id.name_vip)
            laifangshiyou_vip = view.findViewById(R.id.laifangshiyou_vip)
            fangwenduixaing_vip = view.findViewById(R.id.fangwenduixaing_vip)
            shifoushenqingchewei_vip = view.findViewById(R.id.shifoushenqingchewei_vip)
            shifoutongguo_vip = view.findViewById(R.id.shifoutongguo_vip)
        }
    }
}